package com.jlpay.openapi.demo.trans.union;

import com.jlpay.open.jlpay.sdk.java.model.trans.union.request.UnionJsPayRequest;
import com.jlpay.open.jlpay.sdk.java.model.trans.union.response.UnionJsPayResponse;
import com.jlpay.open.jlpay.sdk.java.utils.json.JsonUtils;
import com.jlpay.openapi.demo.JlpayOpenApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author dengwenning
 * @since 2024/9/23
 **/
public class UnionJsPayService {
    private static final Logger LOGGER = LoggerFactory.getLogger(UnionJsPayService.class);

    public static void main(String[] args) {
        UnionJsPayRequest unionJsPayRequest = buildUnionJsPayRequest();
        UnionJsPayResponse unionJsPayResponse = JlpayOpenApiService.openMerchService()
                .post(unionJsPayRequest, UnionJsPayResponse.class);
        LOGGER.info("银联行业码支付下单响应:{}", JsonUtils.toString(unionJsPayResponse));
    }

    private static UnionJsPayRequest buildUnionJsPayRequest() {
        UnionJsPayRequest unionJsPayRequest = new UnionJsPayRequest();

        unionJsPayRequest.setMchId("849584358120018");
        unionJsPayRequest.setTermNo("60131234");
        unionJsPayRequest.setPayType("unionpay");
        unionJsPayRequest.setAppUpIdentifier("UnionPay/1.0");
        unionJsPayRequest.setUserAuthCode("gg47vT2aCMw/utQcfQw==");
        unionJsPayRequest.setOutTradeNo("ld201911023465529");
        unionJsPayRequest.setPaymentValidTime("10");
        unionJsPayRequest.setBody("充值中心-会员充值");
        unionJsPayRequest.setAttach("商城—-易拉宝10个打印纸20箱");
        unionJsPayRequest.setTotalFee("1");
        unionJsPayRequest.setRemark("该订单物流请走顺丰快递");
        unionJsPayRequest.setNotifyUrl("https://help.jlpay.com/api/docs/home");
        unionJsPayRequest.setOpUserId("001");
        unionJsPayRequest.setOpShopId("GD_SZ_001");
        unionJsPayRequest.setDeviceInfo("N50007A8890");
        unionJsPayRequest.setMchCreateIp("123.12.12.123");
        unionJsPayRequest.setLongitude("116.078631");
        unionJsPayRequest.setLatitude("39.71274");
        unionJsPayRequest.setFrontUrl("https://op.jlpay.com/");
        unionJsPayRequest.setFrontFailUrl("https://mf.jlpay.com/sqr?sn=JLTY1567085&ac=CF123AAD");

        return unionJsPayRequest;
    }
}
